
//多维数值的定义引用方法
var cow_skin_type = cc.Class({
    name: 'cow_skin_type',
    properties: {
        cow_status: {
            type: cc.SpriteFrame,
            default: []
        }
    }
}); 
cc.Class({
    extends: cc.Component,
    properties: {
        //设置牛的皮肤多维数组
        cow_skin: {
            type: cow_skin_type,
            default: [],
        } 
       
    },

    onLoad () {
        //随机生成牛
        var cow_type = Math.floor(Math.random()*3)
        this.cow_type = cow_type
        //帧动画
        // 添加帧动画组件
        this.anim_com = this.node.addComponent('frame_anim')
        // 播放
        this.cowWalk()
        // 移动速度
        this.speed_x = Math.random() * 200 + 200
    },
    cowWalk () {
        this.anim_com.sprite_frames = this.cow_skin[this.cow_type].cow_status
        this.anim_com.duration = 0.5
        this.anim_com.play_loop()
    },

    start () {

    },

    update (dt) {
        var move_x = -(this.speed_x * dt)
        this.node.x += move_x
        if (this.node.x < -500) {   // 超出屏幕
            // 移除组件
            this.node.removeFromParent()
        }

    },
});
